package design;

public class leetCode69_mySqrt {
    public int mySqrt(int x) {
        if(x < 0) return -1;
        if(x == 0 || x == 1) return x;
        int start = 0;
        int end = x;
        while (start < end){
            int mid = start + (end - start)/2;
            if(mid > x/mid){
                end = mid;
            }else{
                start = mid;
            }
        }
        return start;
    }

}
